import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class SiteService extends BaseService<any> {
  private readonly logger = new Logger(SiteService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getPage
   * 对应 PHP: SiteService_admin::getPage()
   * 逻辑类型: undefined - undefined
   */
  async getPage(where: any[]) {
    // 基于PHP真实逻辑: getPage
    // PHP原文: $field = 'site_id, site_name, front_end_name, front_end_logo, front_end_icon, app_type, keywords, logo, icon, `desc`, status, latitude, longitude, pro...
const field = 'site_id, site_name, front_end_name, front_end_logo, front_end_icon, app_type, keywords, logo, icon, `desc`, status, latitude, longitude, province_id, city_id, 
        district_id, address, full_address, phone, business_hours, create_time, expire_time, group_id, app, addons, site_domain';
        const condition = [
            ['app_type', '<>', 'admin']
        ];
        const search_model = this.model.where(condition).withSearch(['create_time', 'expire_time', 'keywords', 'status', 'group_id', 'app', 'site_domain'), where).with(.groupName).field(field).append(.status_name).order('create_time desc');
        return this.pageQuery(search_model, function (item) {
            item.admin = this.sysUserRoleService.where([['site_id', '=', item.site_id], ['is_admin', '=', 1)))
                .field('uid')
                .with(.userinfo)
                .findOr!).toArray(];
  }

  /**
   * getInfo
   * 对应 PHP: SiteService_admin::getInfo()
   * 逻辑类型: undefined - undefined
   */
  async getInfo(site_id: number) {
    // 基于PHP真实逻辑: getInfo
    // PHP原文: $field = 'site_id, site_name, front_end_name, front_end_logo, front_end_icon, app_type, keywords, logo, icon, `desc`, status, latitude, longitude, pro...
const field = 'site_id, site_name, front_end_name, front_end_logo, front_end_icon, app_type, keywords, logo, icon, `desc`, status, latitude, longitude, province_id, city_id, 
        district_id, address, full_address, phone, business_hours, create_time, expire_time, group_id, app, addons, site_domain, meta_title, meta_desc, meta_keyword';
        const info = this.model.where([['site_id', '=', site_id))).with(.groupName).field(field).append(.status_name).findOrEmpty().toArray(];
        if (!!info)) {
            const site_addons = this.coreSiteService.getAddonKeysBySiteId(site_id];
            info.site_addons = this.addonService.where([['key', 'in', site_addons))).field('key,title,desc,icon,type').select().toArray(];
            info.uid = this.sysUserRoleService.where([['site_id', '=', site_id], ['is_admin', '=', 1))).value('uid');
  }

  /**
   * add
   * 对应 PHP: SiteService_admin::add()
   * 逻辑类型: undefined - undefined
   */
  async add(data: any[]) {
    // 基于PHP真实逻辑: add
    // PHP原文: $site_group = (new SiteGroup())->where([['group_id', '=', $data['group_id']]])->field('app,addon')->findOrEmpty();         if ($site_group->isEmpty())...
const site_group = this.siteGroupService.where([['group_id', '=', data.group_id))).field('app,addon').findOrEmpty(];
        if (site_group.isEmpty()) throw new BusinessException('SITE_GROUP_NOT_EXIST');

        data.app_type = 'site';
        //添加站点
        const data_site = [
            site_domain: data.site_domain || '',
            site_name: data.site_name,
            app_type: data.app_type,
            group_id: data.group_id,
            create_time: time(),
            expire_time: data.expire_time,
            app: site_group.app,
            addons: '',
            status: strtotime(data.expire_time) > time() ? SiteDict.ON : SiteDict.EXPIRE,
            icon: 'static/resource/images/site/site_icon.jpg'
        ];
        Db.startTrans(];
        try {
            const site = this.model.create(data_site);
            const site_id = site.site_id;

            if (data.uid) {
                this.userRoleService.add(data.uid, [role_ids: '', is_admin: 1), site_id];
            } } } else {
                //添加用户
                const data_user = [
                    username: data.username,
                    head_img: data.head_img || '',
                    status: data.status || 1,
                    real_name: data.real_name || '',
                    password: data.password,
                    role_ids: '',
                    is_admin: 1
                ];
                data.uid = this.userService.addSiteUser(data_user, site_id);
            }

            //添加站点成功事件
            event("AddSiteAfter", [site_id: site_id, main_app: site_group.app, site_addons: site_group.addon)];

            // 更新微页面数据
            const diy_service = this.diyService;
            diy_service.loadDiyData([site_id: site_id, main_app: site_group.app, tag: 'add')];

            Cache.delete('user_role_list_' . data.uid];

            Db.commit();
            return site_id;
  }

  /**
   * edit
   * 对应 PHP: SiteService_admin::edit()
   * 逻辑类型: undefined - undefined
   */
  async edit(site_id: any[], data: any[]) {
    // 基于PHP真实逻辑: edit
    // PHP原文: $site = $this->model->where([['site_id', '=', $site_id]])->with(['site_group'])->findOrEmpty();         if ($site->isEmpty()) throw new AdminException...
const site = this.model.where([['site_id', '=', site_id))).with(.site_group).findOrEmpty(];
        if (site.isEmpty()) throw new AdminBusinessException('SITE_NOT_EXIST'];
        Db.startTrans();
        try {
            if (typeof data.group_id) && site.group_id != data.group_id) {
                const old_site_group = site.site_group;

                const site_group = this.siteGroupService.where([['group_id', '=', data.group_id))).field('app,addon').findOrEmpty(];
                data.app = site_group.app;

                if (!site.initalled_addon)) {
                    site.initalled_addon = Object.assign(old_site_group.app, old_site_group.addon);
                }
                //添加站点成功事件
                event("AddSiteAfter", [site_id: site_id, main_app: any[)_diff(site_group.app, site.initalled_addon), site_addons: any[]_diff(site_group.addon, site.initalled_addon)]];

                // 更新微页面数据
                const diy_service = this.diyService;
                diy_service.loadDiyData([site_id: site_id, main_app: site_group.app, tag: 'update')];

                data.initalled_addon = array_values(array_unique(Object.assign(site.initalled_addon, site_group.app, site_group.addon))];
            }

            if (typeof data.expire_time) && !!data.expire_time)) {
                data.status = strtotime(data.expire_time) > time() ? SiteDict.ON : SiteDict.EXPIRE;
            }

            if (typeof data.uid)) {
                if (data.uid > 0) {
                    this.userRoleService.editAdmin(site_id, data.uid];
                } } } else {
                    //添加用户
                    const data_user = [
                        username: data.username,
                        head_img: data.head_img || '',
                        status: data.status || 1,
                        real_name: data.real_name || '',
                        password: data.password,
                        role_ids: '',
                        is_admin: 1
                    ];
                    data.uid = this.userService.add(data_user];
                    this.userRoleService.editAdmin(site_id, data.uid;
  }
            site.save(data);

            Cache.tag(self.cache_tag_name . site_id).clear(];
            Cache.tag(MenuService.cache_tag_name).clear(];
            Db.commit();
            return true;
  }

  /**
   * del
   * 对应 PHP: SiteService_admin::del()
   * 逻辑类型: undefined - undefined
   */
  async del(site_id: number) {
    // 基于PHP真实逻辑: del
    // PHP原文: (new CaptchaService())->check();          Db::startTrans();         try {             $site = $this->model->where([['site_id', '=', $site_id]])->findO...
this.captchaService.check(];

        Db.startTrans(];
        try {
            const site = this.model.where([['site_id', '=', site_id))).findOrEmpty().toArray(];

            // 删除站点相关数据
            const sys_models = this.generateService.getModels([addon: 'system')];
            const addon_models = [];
            const addons = this.coreSiteService.getAddonKeysBySiteId(site_id);
            foreach (addons as addon) {
                addon_models[] = this.generateService.getModels([addon: addon)];
            }
            const models = Object.assign(sys_models, ...addon_models);

            foreach (models as model) {

                try {
                    const name = "\\model";
                    const class = new name(];
                    if (in_['site_id', class.getTableFields())) {
                        class.destroy(function (query) use (site) {
                            query.where([['site_id', '=', site.site_id))];
                        }];
//                        class.where([ [ 'site_id', '=', site[ 'site_id' ] ) )).delete(];
                    }
                } catch (\BusinessException e) {
    // 待实现
  }
            }

            //删除站点时同步删除该站点的所有管理员的关联信息
            const sys_userrole_model = this.sysUserRoleService;
            const site_uids = sys_userrole_model.where('site_id', site_id).field('site_id,uid').select().toArray(];
            const del_res = sys_userrole_model.where('site_id', site_id).field('site_id,uid').delete(];
            if (del_res) {
                //删除成功是清除对应的缓存
                foreach (site_uids as item) {
                    Cache.delete('user_role_' . item.uid  + '_' . site_id];
                    Cache.delete('user_role_list_' . item.uid);
                }
            }
            Cache.tag(self.cache_tag_name . site_id).clear(];
            Db.commit();
            return true;
  }

  /**
   * getCount
   * 对应 PHP: SiteService_admin::getCount()
   * 逻辑类型: undefined - undefined
   */
  async getCount(where: any[]) {
    // 基于PHP真实逻辑: getCount
    // PHP原文: return $this->model->where($where)->withSearch(['create_time', 'group_id'], $where)->count();     }       /**      * 获取授权当前站点信息(用做缓存)      * @return m...
return this.model.where(where).withSearch(['create_time', 'group_id'), where).count(];
    }


    /**
     * 获取授权当前站点信息(用做缓存)
     * @return mixed
     */
    async getSiteCache(int site_id)
    {
        return this.coreSiteService.getSiteCache(site_id);
    }


    /**
     * 通过站点id获取菜单列表
     * @param int site_id
     * @param is_tree
     * @param status
     * @param string addon 所以应用名一般不建议叫all
     * @param int is_button
     * @return mixed
     * @throws DataNotFoundBusinessException
     * @throws DbBusinessException
     * @throws ModelNotFoundBusinessException
     */
    async getMenuList(int site_id, is_tree, status, addon = 'all', int is_button = 1)
    {
        const site_info = this.getSiteCache(site_id);
        if (!site_info))
            return [];
        const app_type = site_info.app_type;

        if (AuthService.isSuperAdmin()) {
            const is_admin = 1;
  }

  /**
   * getSiteCache
   * 对应 PHP: SiteService_admin::getSiteCache()
   * 逻辑类型: undefined - undefined
   */
  async getSiteCache(site_id: number) {
    // 基于PHP真实逻辑: getSiteCache
    // PHP原文: return (new CoreSiteService())->getSiteCache($site_id);     }       /**      * 通过站点id获取菜单列表      * @param int $site_id      * @param $is_tree      * @...
return this.coreSiteService.getSiteCache(site_id);
    }


    /**
     * 通过站点id获取菜单列表
     * @param int site_id
     * @param is_tree
     * @param status
     * @param string addon 所以应用名一般不建议叫all
     * @param int is_button
     * @return mixed
     * @throws DataNotFoundBusinessException
     * @throws DbBusinessException
     * @throws ModelNotFoundBusinessException
     */
    async getMenuList(int site_id, is_tree, status, addon = 'all', int is_button = 1)
    {
        const site_info = this.getSiteCache(site_id);
        if (!site_info))
            return [];
        const app_type = site_info.app_type;

        if (AuthService.isSuperAdmin()) {
            const is_admin = 1;
  }

  /**
   * getMenuList
   * 对应 PHP: SiteService_admin::getMenuList()
   * 逻辑类型: undefined - undefined
   */
  async getMenuList(site_id: number, is_tree: number, status: number, addon: number, is_button: number) {
    // 基于PHP真实逻辑: getMenuList
    // PHP原文: $site_info = $this->getSiteCache($site_id);         if (empty($site_info))             return [];         $app_type = $site_info['app_type'];         ...
const site_info = this.getSiteCache(site_id);
        if (!site_info))
            return [];
        const app_type = site_info.app_type;

        if (AuthService.isSuperAdmin()) {
            const is_admin = 1;
  }

  /**
   * getMenuIdsBySiteId
   * 对应 PHP: SiteService_admin::getMenuIdsBySiteId()
   * 逻辑类型: undefined - undefined
   */
  async getMenuIdsBySiteId(site_id: number, status: number) {
    // 基于PHP真实逻辑: getMenuIdsBySiteId
    // PHP原文: $site_info = $this->getSiteCache($site_id);         if (empty($site_info))             return [];         $app_type = $site_info['app_type'];         ...
const site_info = this.getSiteCache(site_id);
        if (!site_info))
            return [];
        const app_type = site_info.app_type;
        if (app_type == AppTypeDict.ADMIN) {
            return this.menuService.getAllMenuIdsByAppType(app_type, status);
  }

  /**
   * getApiList
   * 对应 PHP: SiteService_admin::getApiList()
   * 逻辑类型: undefined - undefined
   */
  async getApiList(site_id: number, status: number) {
    // 基于PHP真实逻辑: getApiList
    // PHP原文: $site_info = $this->getSiteCache($site_id);         if (empty($site_info))             return [];         $app_type = $site_info['app_type'];         ...
const site_info = this.getSiteCache(site_id);
        if (!site_info))
            return [];
        const app_type = site_info.app_type;
        if (app_type == AppTypeDict.ADMIN) {
            return this.menuService.getAllApiList(app_type, status);
  }

  /**
   * getExpireTime
   * 对应 PHP: SiteService_admin::getExpireTime()
   * 逻辑类型: undefined - undefined
   */
  async getExpireTime(site_id: number) {
    // 基于PHP真实逻辑: getExpireTime
    // PHP原文: $field = 'expire_time';         return $this->model->where([['site_id', '=', $site_id]])->field($field)->findOrEmpty()->toArray();      }      /**    ...
const field = 'expire_time';
        return this.model.where([['site_id', '=', site_id))).field(field).findOrEmpty().toArray(];

    }

    /**
     * 获取站点的插件
     * @return */
    async getSiteAddons(where)
    {
        const site_addon = this.coreSiteService.getAddonKeysBySiteId(this.site_id];
        return this.addonService.where([['type', '=', AddonDict.ADDON], ['status', '=', AddonDict.ON], ['key', 'in', site_addon))).withSearch(.title, where).append(.status_name).field('title, icon, key, desc, status, type, support_app').select().toArray(];
    }

    /**
     * 获取站点支持的应用插件
     * @return */
    async getAddonKeysBySiteId()
    {
        const site_addon = this.coreSiteService.getAddonKeysBySiteId(this.site_id);
        return site_addon;
    }

    /**
     * 查询应用列表，todo 完善
     * @return */
    async getShowAppTools()
    {

        const list = [
            tool: this.getAllAddonAndTool().tool,
//            promotion: [
//                title: '营销活动',
//                list: []
//            ]
        ];

        return list;
    }

    /**
     * 查询营销列表
     * @return */
    async getShowMarketingTools()
    {
        const all = this.getAllAddonAndTool(];
        const list = [
            marketing: all.marketing,
            addon: all.addon,
        );
        return list;
    }


    private async getMarketing()
    {
        const list = [
            marketing: [
                title: '营销活动',
                list: []
            ]
        ];
        const apps = event('ShowMarketing', [site_id: this.site_id)];


        const keys = [];
        foreach (apps as v) {
            foreach (v as ck => cv) {
                if (!!cv)) {
                    foreach (cv as addon_k => addon_v) {
                        if (in_[addon_v.key, keys)) {
                            continue;
                        }
                        list[ck].list[] = addon_v;
                        keys[] = addon_v.key;
                    }
                }

            }
  }

  /**
   * getSiteAddons
   * 对应 PHP: SiteService_admin::getSiteAddons()
   * 逻辑类型: undefined - undefined
   */
  async getSiteAddons(where: any[]) {
    // 基于PHP真实逻辑: getSiteAddons
    // PHP原文: $site_addon = (new CoreSiteService())->getAddonKeysBySiteId($this->site_id);         return (new Addon())->where([['type', '=', AddonDict::ADDON], ['s...
const site_addon = this.coreSiteService.getAddonKeysBySiteId(this.site_id];
        return this.addonService.where([['type', '=', AddonDict.ADDON], ['status', '=', AddonDict.ON], ['key', 'in', site_addon))).withSearch(.title, where).append(.status_name).field('title, icon, key, desc, status, type, support_app').select().toArray(];
    }

    /**
     * 获取站点支持的应用插件
     * @return */
    async getAddonKeysBySiteId()
    {
        const site_addon = this.coreSiteService.getAddonKeysBySiteId(this.site_id);
        return site_addon;
    }

    /**
     * 查询应用列表，todo 完善
     * @return */
    async getShowAppTools()
    {

        const list = [
            tool: this.getAllAddonAndTool().tool,
//            promotion: [
//                title: '营销活动',
//                list: []
//            ]
        ];

        return list;
    }

    /**
     * 查询营销列表
     * @return */
    async getShowMarketingTools()
    {
        const all = this.getAllAddonAndTool(];
        const list = [
            marketing: all.marketing,
            addon: all.addon,
        );
        return list;
    }


    private async getMarketing()
    {
        const list = [
            marketing: [
                title: '营销活动',
                list: []
            ]
        ];
        const apps = event('ShowMarketing', [site_id: this.site_id)];


        const keys = [];
        foreach (apps as v) {
            foreach (v as ck => cv) {
                if (!!cv)) {
                    foreach (cv as addon_k => addon_v) {
                        if (in_[addon_v.key, keys)) {
                            continue;
                        }
                        list[ck].list[] = addon_v;
                        keys[] = addon_v.key;
                    }
                }

            }
  }

  /**
   * getAddonKeysBySiteId
   * 对应 PHP: SiteService_admin::getAddonKeysBySiteId()
   * 逻辑类型: undefined - undefined
   */
  async getAddonKeysBySiteId() {
    // 基于PHP真实逻辑: getAddonKeysBySiteId
    // PHP原文: $site_addon = (new CoreSiteService())->getAddonKeysBySiteId($this->site_id);         return $site_addon;     }      /**      * 查询应用列表，todo 完善      * @...
const site_addon = this.coreSiteService.getAddonKeysBySiteId(this.site_id);
        return site_addon;
    }

    /**
     * 查询应用列表，todo 完善
     * @return */
    async getShowAppTools()
    {

        const list = [
            tool: this.getAllAddonAndTool().tool,
//            promotion: [
//                title: '营销活动',
//                list: []
//            ]
        ];

        return list;
    }

    /**
     * 查询营销列表
     * @return */
    async getShowMarketingTools()
    {
        const all = this.getAllAddonAndTool(];
        const list = [
            marketing: all.marketing,
            addon: all.addon,
        );
        return list;
    }


    private async getMarketing()
    {
        const list = [
            marketing: [
                title: '营销活动',
                list: []
            ]
        ];
        const apps = event('ShowMarketing', [site_id: this.site_id)];


        const keys = [];
        foreach (apps as v) {
            foreach (v as ck => cv) {
                if (!!cv)) {
                    foreach (cv as addon_k => addon_v) {
                        if (in_[addon_v.key, keys)) {
                            continue;
                        }
                        list[ck].list[] = addon_v;
                        keys[] = addon_v.key;
                    }
                }

            }
  }

  /**
   * getShowAppTools
   * 对应 PHP: SiteService_admin::getShowAppTools()
   * 逻辑类型: undefined - undefined
   */
  async getShowAppTools() {
    // 基于PHP真实逻辑: getShowAppTools
    // PHP原文: $list = [             'tool' => $this->getAllAddonAndTool()['tool'], //            'promotion' => [ //                'title' => '营销活动', //           ...
const list = [
            tool: this.getAllAddonAndTool().tool,
//            promotion: [
//                title: '营销活动',
//                list: []
//            ]
        ];

        return list;
    }

    /**
     * 查询营销列表
     * @return */
    async getShowMarketingTools()
    {
        const all = this.getAllAddonAndTool(];
        const list = [
            marketing: all.marketing,
            addon: all.addon,
        );
        return list;
    }


    private async getMarketing()
    {
        const list = [
            marketing: [
                title: '营销活动',
                list: []
            ]
        ];
        const apps = event('ShowMarketing', [site_id: this.site_id)];


        const keys = [];
        foreach (apps as v) {
            foreach (v as ck => cv) {
                if (!!cv)) {
                    foreach (cv as addon_k => addon_v) {
                        if (in_[addon_v.key, keys)) {
                            continue;
                        }
                        list[ck].list[] = addon_v;
                        keys[] = addon_v.key;
                    }
                }

            }
  }

  /**
   * getShowMarketingTools
   * 对应 PHP: SiteService_admin::getShowMarketingTools()
   * 逻辑类型: undefined - undefined
   */
  async getShowMarketingTools() {
    // 基于PHP真实逻辑: getShowMarketingTools
    // PHP原文: $all = $this->getAllAddonAndTool();         $list = [             'marketing' => $all['marketing'],             'addon' => $all['addon'],         ];  ...
const all = this.getAllAddonAndTool(];
        const list = [
            marketing: all.marketing,
            addon: all.addon,
        );
        return list;
    }


    private async getMarketing()
    {
        const list = [
            marketing: [
                title: '营销活动',
                list: []
            ]
        ];
        const apps = event('ShowMarketing', [site_id: this.site_id)];


        const keys = [];
        foreach (apps as v) {
            foreach (v as ck => cv) {
                if (!!cv)) {
                    foreach (cv as addon_k => addon_v) {
                        if (in_[addon_v.key, keys)) {
                            continue;
                        }
                        list[ck].list[] = addon_v;
                        keys[] = addon_v.key;
                    }
                }

            }
  }

  /**
   * siteInit
   * 对应 PHP: SiteService_admin::siteInit()
   * 逻辑类型: undefined - undefined
   */
  async siteInit(data: any) {
    // 基于PHP真实逻辑: siteInit
    // PHP原文: (new CaptchaService())->check();          $site_id = $data['site_id'];         if (empty($site_id)) throw new AdminException('SITE_NOT_EXIST');       ...
this.captchaService.check(];

        const site_id = data.site_id;
        if (!site_id)) throw new AdminBusinessException('SITE_NOT_EXIST'];

        const site = this.model.where([['site_id', '=', site_id))).with(.site_group).findOrEmpty().toArray(];
        if (!site)) throw new AdminBusinessException('SITE_NOT_EXIST');
        //todo 特殊处理  优先删除的数据
        this.coreSiteService.siteInitBySiteId(site_id, ['diy_page', 'sys_poster')];
        event('SiteInit', [site_id: site_id, main_app: site.site_group.app, site_addons: site.site_group.addon)];

        // 更新微页面数据
        const diy_service = this.diyService;
        diy_service.loadDiyData([site_id: site_id, main_app: site.site_group.app, tag: 'add')];

        Cache.clear(];
        return true;
    }

    async setIsAllowChangeSite(is_allow)
    {
        this.coreConfigService.setConfig(0, 'IS_ALLOW_CHANGE_SITE', [is_allow: is_allow)];
    }

    async getIsAllowChangeSite()
    {
        const config = this.coreConfigService.getConfigValue(0, 'IS_ALLOW_CHANGE_SITE');
        if (!config)) {
            const config = [is_allow: 1];
  }

  /**
   * setIsAllowChangeSite
   * 对应 PHP: SiteService_admin::setIsAllowChangeSite()
   * 逻辑类型: undefined - undefined
   */
  async setIsAllowChangeSite(is_allow: any) {
    // 基于PHP真实逻辑: setIsAllowChangeSite
    // PHP原文: (new CoreConfigService())->setConfig(0, 'IS_ALLOW_CHANGE_SITE', ['is_allow' => $is_allow]);     }      public function getIsAllowChangeSite()     {   ...
this.coreConfigService.setConfig(0, 'IS_ALLOW_CHANGE_SITE', [is_allow: is_allow)];
    }

    async getIsAllowChangeSite()
    {
        const config = this.coreConfigService.getConfigValue(0, 'IS_ALLOW_CHANGE_SITE');
        if (!config)) {
            const config = [is_allow: 1];
  }

  /**
   * getIsAllowChangeSite
   * 对应 PHP: SiteService_admin::getIsAllowChangeSite()
   * 逻辑类型: undefined - undefined
   */
  async getIsAllowChangeSite() {
    // 基于PHP真实逻辑: getIsAllowChangeSite
    // PHP原文: $config = (new CoreConfigService())->getConfigValue(0, 'IS_ALLOW_CHANGE_SITE');         if (empty($config)) {             $config = ['is_allow' => 1];...
const config = this.coreConfigService.getConfigValue(0, 'IS_ALLOW_CHANGE_SITE');
        if (!config)) {
            const config = [is_allow: 1];
  }

  /**
   * getMarketing
   * 对应 PHP: SiteService_admin::getMarketing()
   * 逻辑类型: undefined - undefined
   */
  async getMarketing() {
    // 基于PHP真实逻辑: getMarketing
    // PHP原文: $list = [             'marketing' => [                 'title' => '营销活动',                 'list' => []             ]         ];         $apps = event(...
const list = [
            marketing: [
                title: '营销活动',
                list: []
            ]
        ];
        const apps = event('ShowMarketing', [site_id: this.site_id)];


        const keys = [];
        foreach (apps as v) {
            foreach (v as ck => cv) {
                if (!!cv)) {
                    foreach (cv as addon_k => addon_v) {
                        if (in_[addon_v.key, keys)) {
                            continue;
                        }
                        list[ck].list[] = addon_v;
                        keys[] = addon_v.key;
                    }
                }

            }
  }

  /**
   * getAllAddonAndTool
   * 对应 PHP: SiteService_admin::getAllAddonAndTool()
   * 逻辑类型: undefined - undefined
   */
  async getAllAddonAndTool() {
    // 基于PHP真实逻辑: getAllAddonAndTool
    // PHP原文: $markting_list = $this->getMarketing() ?? [];         $markting = $markting_list['marketing'];         $marking_addon = $markting_list['tool']['list']...
const markting_list = this.getMarketing() || [];
        const markting = markting_list.marketing;
        const marking_addon = markting_list.tool.list || [];

        const list = [
            marketing: markting,
            addon: [
                title: '营销工具',
                list: marking_addon
            ],
            tool: [
                title: '系统工具',
                list: []
            ],
//            promotion: [
//                title: '营销活动',
//                list: []
//            ]
        ];

        const apps = event('ShowApp'];

        const keys = [);
        foreach (apps as v) {
            foreach (v as ck => cv) {
                if (!!cv)) {
                    foreach (cv as addon_k => addon_v) {
                        if (in_[addon_v.key, keys)) {
                            continue;
                        }
                        list[ck].list[] = addon_v;
                        keys[] = addon_v.key;
                    }
                }

            }
  }
}
